<template>
  <a-config-provider :getPopupContainer="getPopupContainer" :locale="zhCN">
    <BasicLayout />
  </a-config-provider>
</template>

<script setup>
import 'jquery'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.bundle.min.js'
import BasicLayout from '@/layouts/BasicLayout.vue'
import 'bootstrap-icons/font/bootstrap-icons.css'
import { useLoginStore } from '@/stores/loginStore.js'
import { useToastStore } from '@/stores/toastStore.js'
import router from '../src/router/index.js'
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import { message } from 'ant-design-vue'

const loginStore = useLoginStore()
const toastStore = useToastStore()

function getPopupContainer(el, dialogContext) {
  if (dialogContext) {
    return dialogContext.getDialogWrap()
  } else {
    return document.body
  }
}

const fetchCurrentUser = async () => {
  try {
    const res = await loginStore.fetchUserInfo()
    if (res?.data?.code === 0 && res?.data?.data) {
      loginStore.setLoginuser(res.data.data)
    } else {
      message.error(res?.data?.message)
      setTimeout(() => {
        router.push({ name: 'login' })
      }, 100)
    }
  } catch (e) {
    toastStore.set(true, e.message)
  }
}

fetchCurrentUser()
</script>

<style scoped>
* {
  margin: 0;
}

body {
  background-image: url('./assets/background.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
</style>
